// RulerView.m
// By Jayson Adams, NeXT Developer Support Team
// Modified for 3.0 by Ali Ozer, May '92
// You may freely copy, distribute and reuse the code in this example.
// NeXT disclaims any warranty of any kind, expressed or implied, as to its
// fitness for any particular use.

#import <dpsclient/psops.h>
#import <math.h>

#import "RulerView.h"

@implementation RulerView

#define INCH_MARK_LENGTH (NX_HEIGHT(&bounds) * 0.75)
#define HALFINCH_MARK_LENGTH (NX_HEIGHT(&bounds) * 0.5)
#define QUARTERINCH_MARK_LENGTH (NX_HEIGHT(&bounds) * 0.25)

- drawSelf:(const NXRect *)rects :(int)rectCount
{
    NXCoord start = floor(NX_X(rects) / 72.0) * 72.0;
    NXCoord end = ceil(NX_MAXX(rects) / 72.0) * 72.0;

    PSsetgray (NX_LTGRAY);
    NXRectFill (rects);
    
    PSmoveto (start, 1.0);
    PSlineto (end, 1.0);
    while (start <= end) {
    	// Userpaths would really help out here. Exercise for the reader...
	PSmoveto (start, 0.0);
	PSrlineto (0.0, INCH_MARK_LENGTH);
	PSmoveto (start + 36.0, 0.0);
	PSrlineto (0.0, HALFINCH_MARK_LENGTH);
	PSmoveto (start + 18.0, 0.0);
	PSrlineto (0.0, QUARTERINCH_MARK_LENGTH);
	PSmoveto (start + 54.0, 0.0);
	PSrlineto (0.0, QUARTERINCH_MARK_LENGTH);
	start += 72.0;
    }

    PSsetlinewidth (0.0);
    PSsetgray (NX_BLACK);
    PSstroke();

    return self;
}

@end
